package view {
	import flash.display.Sprite;
	
	/**
	 * ...
	 * @author flyingSnow
	 */
	public final class Square extends Sprite {
		private var _state:uint;
		private var _colorSquares:Array;
		private var _colorIndex:int = 0;
		private var _row:int;
		private var _column:int;
		
		public static const COLORS:Array = [0xff0000,0x007700,0x0000ff,0xF8BC1F];
		public static const LIGHT_PT_INDEX:int = 4;
		public static const UNABLED_INDEX:int = 5;
		public static const STANDARD_SIZE:int = 30;
		
		public function Square() {
			addSquare();
			addLightPoint();
			addUnabled();
			state = 0;
			colorIndex = 0;
		}
		
		private function addUnabled():void {
			var squ:Sprite = new Sprite();
			addChild(squ);
			squ.graphics.beginFill(0xB7B7B7);
			squ.graphics.drawRoundRect(0, 0, STANDARD_SIZE, STANDARD_SIZE, 5, 5);
			_colorSquares.push(squ);
		}
		
		private function addLightPoint():void {
			var squ:Sprite = new Sprite();
			addChild(squ);
			squ.graphics.beginFill(0xffffff);
			squ.graphics.drawRect(1, 1, STANDARD_SIZE-2, STANDARD_SIZE-2);
			squ.graphics.endFill();
			
			squ.graphics.lineStyle(0);			
			squ.graphics.beginFill(0xffffff);			
			squ.graphics.drawCircle(STANDARD_SIZE / 2, STANDARD_SIZE / 2, STANDARD_SIZE / 3);
			squ.graphics.endFill();
			_colorSquares.push(squ);
		}
		
		private function addSquare():void {
			_colorSquares = [];
			
			for (var i:int = 0; i < COLORS.length; i++ ) {
				var squ:Sprite = new Sprite();
				addChild(squ);
				squ.graphics.beginFill(COLORS[i]);
				//squ.graphics.drawRect( 0, 0, STANDARD_SIZE, STANDARD_SIZE);
				squ.graphics.drawRoundRect(0, 0, STANDARD_SIZE, STANDARD_SIZE, 5, 5);
				_colorSquares.push(squ);
			}					
		}
		
		public function get state():uint {
			return _state;
		}
		
		public function set state(value:uint):void {
			_state = value>0?1:0;
			alpha = _state;
		}
		
		public function get colorIndex():int {
			return _colorIndex;
		}
		
		public function set colorIndex(value:int):void {
			_colorIndex = value;
			for (var i:int = 0; i < _colorSquares.length; i++ ) {
				_colorSquares[i]["visible"]=false;
			}
			_colorSquares[value]["visible"] = true;
		}
		
		public function get row():int { return _row; }
		
		public function set row(value:int):void {
			_row = value;
		}
		
		public function get column():int { return _column; }
		
		public function set column(value:int):void {
			_column = value;
		}
		
		
	}

}